import 'package:flutter/material.dart';
import 'package:flutter_world_cup/flutter_world_cup.dart';

class WorldCupPage extends StatefulWidget {
  const WorldCupPage({super.key});

  @override
  State<WorldCupPage> createState() => _WorldCupPageState();
}

class _WorldCupPageState extends State<WorldCupPage> {
  Stream<String>? _countriesStream;

  @override
  void initState() {
    super.initState();
    _countriesStream = FlutterWorldCup.countriesStream;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('World Cup Host Countries')),
      body: StreamBuilder<String>(
        stream: _countriesStream,
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Center(child: CircularProgressIndicator());
          } else if (snapshot.hasError) {
            return Center(child: Text('Error: ${snapshot.error}'));
          } else if (snapshot.hasData) {
            return Center(
                child: Text('Host Country: ${snapshot.data}',
                    style: const TextStyle(fontSize: 24)));
          } else {
            return const Center(child: Text('No more countries'));
          }
        },
      ),
    );
  }
}
